﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPIS.GERP.ESS.BLL;
using KPIS.GERP.ESS.MODEL;
using KPIS.GERP.ESS.APP.App_UI.Commons;
using KPIS.GERP.ESS.APP.App_UI.Forms;

namespace KPIS.GERP.ESS.APP.App_UI.UserControls
{
    public partial class Mail_Return : System.Web.UI.UserControl
    {
        Main main = new Main();
        ESS.BLL.B_MessageSend send = new ESS.BLL.B_MessageSend();

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void LoadData(string strSendSeq)
        {
            lblSendSeq.Text = strSendSeq;
            M_MessageSend info = send.GetInfo(strSendSeq);
            M_MessageSend infoPrev = send.GetInfo(info.from_send_seq.ToString());
            string strEvent = "";

            switch (infoPrev.ref_type)
            {
                case "bgm_project_operation":
                    strEvent = "ขออนุมัติดำเนินงาน";
                    break;
                case "fim_money_requests":
                    strEvent = "ขอเบิก/ขอเยืม";
                    break;
                case "fim_payments":
                    strEvent = "จ่ายเงิน";
                    break;
                case "bgm_request":
                    strEvent = "ของบประมาณ";
                    break;
            }

            lblSenderName.Text = info.from_user_name;
            lblSendDate.Text = info.send_date.HasValue ? info.send_date.Value.ToShortDateString() : "-";
            lblEvent.Text = strEvent;
            lblRefNo.Text = info.ref_no;
            lblRefName.Text = info.send_text;
            lblRemarks.Text = info.remarks;
        }

        protected void cmdRead_Click(object sender, EventArgs e)
        {
            var model = send.GetInfo(lblSendSeq.Text);
            model.message_status = "3";
            model.updated_by = SsMng.EmpSeqI;
            model.updated_when = DateTime.Now;
            send.UpdateMessageStatus(model);
            main.MessageAlert(Page, "บันทึกเรียบร้อย");

            ((TaskListsPopUp)Page).cmdViewRequest_Click(null, null);
        }
    }
}